home *** CD-ROM | disk | FTP | other *** search
/ ftp.alaska-software.com / 2014.06.ftp.alaska-software.com.tar / ftp.alaska-software.com / 3pp / mxsetup.old / {app} / ListProg.prg < prev    next >
Text File  |  2001-09-14  |  14KB  |  479 lines

  1. ***********************************************************************
  2. * MxListProg.PRG
  3. ***********************************************************************
  4. *  Created 12/23/1999 - jpc
  5. *  Prints a user specified ASCII file to the Printer with Line Numbers.
  6. ***********************************************************************
  7.  
  8. #include "Xbp.ch"
  9. #include "Font.ch"
  10. #include "Common.ch"
  11. #include "Appevent.ch"
  12. #include "Gra.ch"
  13. #include "Directry.ch"
  14.  
  15. #define xbeUser_DateMarked    xbeP_User + 1
  16. #define xbeUser_Print        xbeP_User + 2
  17. #define xbeUser_Browse        xbeP_User + 3
  18.  
  19. PROCEDURE MxListProg()
  20.  
  21.     LOCAL oDlg, mp1, mp2, oFocus:=setAppfocus(), oWin, oPrinterPS, oXbp, oXbpp
  22.     LOCAL cFileName, lExit := .F., aFiles := {}, i, aDates := {}, aSize := {}, aPos := {}
  23.     LOCAL cFile := "", cOldfile := "", cDir := "C:\", aFileNames := {}
  24.  
  25.     PRIVATE lUpdate := .F.
  26.  
  27.     if alltrim(upper(procName(1)))=="MAIN"
  28.         cDir := CurDrive()+":\"+CurDir()
  29.     endif
  30.  
  31.     aSize := setAppWindow():currentSize()
  32.     aPos := setAppWindow():currentPos()
  33.  
  34.     oDlg := XbpDialog():new(AppDeskTop(),SetAppWindow():drawingArea,{aPos[1]+5,aPos[2]+(aSize[2]-170)},{aSize[1]-10,130})
  35.     oDlg:tasklist    := .F.
  36.     oDlg:title        := "Print Text Files with Line Numbers - If WildCards are in [File Name], [Modified Since] will be used to Validate"
  37.     oDlg:close        := {|| lExit := .T. }
  38.     oDlg:border        := XBPDLG_RAISEDBORDERTHIN_FIXED
  39.     oDlg:SetFontCompoundName("9.Arial Bold")
  40.     oDlg:create()
  41.  
  42.     oFocus    := SetAppFocus( oDlg )
  43.  
  44.     oDlg:setModalState(XBP_DISP_APPMODAL)
  45.  
  46.     oXbp    := XbpStatic():new()
  47.     oXbp:caption := "Print File(s):"
  48.     oXbp:options := XBPSTATIC_TEXT_VCENTER
  49.     oXbp:create( oDlg:drawingarea, , {10,70}, {95,20} )
  50.  
  51.     oXbp1 := XbpSle():new()
  52.     oXbp1:dataLink := {|x| IIf( x==NIL , "" , cFileName := x ) }
  53.     oXbp1:clipSiblings := .T.
  54.     oXbp1:bufferlength := 250
  55.     oXbp1:border := .T.
  56.     oXbp1:tabstop := .F.
  57.     oXbp1:editable := .T.
  58.     oXbp1:create( oDlg:drawingarea, , {105,70}, {aSize[1]-135,20} )
  59.     oXbp1:setdata(cFile)
  60.     oXbp1:setname(1)
  61.     oXbp1:helpLink := ToolHelpLabel():new()
  62.     oXbp1:cargo := procname()+"1"
  63.     cDirectry := oXbp1:editbuffer()
  64.     oXbp1:setMarked( {oXbp1:bufferlength,oXbp1:bufferlength} )
  65.  
  66.     oXbp    := XbpStatic():new()
  67.     oXbp:caption := "Modified Since:"
  68.     oXbp:options := XBPSTATIC_TEXT_VCENTER
  69.     oXbp:create( oDlg:drawingarea, , {10,40}, {95,20} )
  70.  
  71.     for i := 365 to 1 step -1
  72.         aAdd(aDates,dtoc(date()+1-i))
  73.     next i
  74.  
  75.     oDateBox    := XbpComboBox():new()
  76.     oDateBox:clipSiblings := .F.
  77.     oDateBox:type := XBPCOMBO_DROPDOWNLIST
  78.     oDateBox:Markmode    := XBPLISTBOX_MM_SINGLE
  79.     oDateBox:SetFontCompoundName("8.Arial Bold")
  80.     oDateBox:datalink := {|x| IIf( x==NIL, {nDate}, nDate := x[1] )}
  81.     oDateBox:create(oDlg:drawingarea , , {105,-340}, {80,400} )
  82.     oDateBox:setname(2)
  83.     oDateBox:helpLink := ToolHelpLabel():new()
  84.     oDateBox:cargo := procname()+"2"
  85.     AEval(aDates, {|c| oDateBox:addItem(c)} )
  86.     nDate := len(aDates)-1
  87.     oDateBox:itemMarked    :=    {|mp1,mp2,obj| ;
  88.             mp1    := obj:getdata()[1],1,;
  89.             PostAppEvent( xbeUser_DateMarked,mp1 ) }
  90.     oDateBox:setData()
  91.     oDateBox:show()
  92.  
  93.     oXbp := XbpCheckbox():new()
  94.     oXbp:caption := "Update File"
  95.     oXbp:create(oDlg:drawingArea , , {250,40}, {100,20} )
  96.     oXbp:selected := {| mp1, mp2, oChk| lUpdate := mp1}
  97.     oXbp:setdata(lUpDate)
  98.     oXbp:setname(1)
  99.  
  100.     oXbp := XBPPushButton():new( oDlg:drawingArea, , {aSize[1]-200,10}, {80,24}, { { XBP_PP_COMPOUNDNAME, "10.Alaska CRT" } } )
  101.     oXbp:caption := "Browse"
  102.     oXbp:clipSiblings    := .T.
  103.     oXbp:create()
  104.     oXbp:activate := { || PostAppEvent(xbeUser_Browse) }
  105.  
  106.     oXbpp := XBPPushButton():new( oDlg:drawingArea, , {aSize[1]-110,10}, {80,24}, { { XBP_PP_COMPOUNDNAME, "10.Alaska CRT" } } )
  107.     oXbpp:caption := "Print"
  108.     oXbpp:clipSiblings    := .T.
  109.     oXbpp:create()
  110.     oXbpp:activate := { || PostAppEvent(xbeUser_Print) }
  111.     setAppFocus(oXbpp)
  112.  
  113.     oDlg:show()
  114.  
  115.     do while !lExit
  116.         if empty(aFileNames)
  117.             oDlg:disable()
  118.  
  119.             oFiles := FileDialog():new()
  120.             oFiles:fileMustExist := .T.
  121.             oFiles:center := .F.
  122.             oFiles:title  := "Select a File"
  123.             oFiles:filter := { { "Program Files (*.PRG)", "*.PRG" },;
  124.                              { "Project Files (*.XPJ)", "*.XPJ" },;
  125.                              { "Text Files (*.TXT)", "*.TXT" },;
  126.                              { "All Files (*.*)", "*.*" } }
  127.             oFiles:startPath := cDir
  128.             oFiles:allowMultiSelect := .T.
  129.             oFiles:create(,,{aPos[1]+110,aPos[2]+(aSize[2]-430)})
  130.  
  131.             aFileNames := oFiles:aFileNames
  132.  
  133.             SetAppFocus(oDlg)
  134.             oDlg:enable()
  135.             SetAppFocus(oXbpp)
  136.         endif
  137.         if !empty(aFileNames)
  138.             for i:=1 to len(aFileNames)
  139.                 if i==1
  140.                     cFile := aFileNames[1]
  141.                 else
  142.                     cFile := cFile+right(aFileNames[i],len(aFileNames[i])-rat("\",aFileNames[1]))
  143.                 endif
  144.                 if i<len(aFileNames)
  145.                     cFile := cFile+","
  146.                 endif
  147.             next i
  148.         else
  149.             lExit := .T.
  150.             loop
  151.         endif
  152.         if cOldFile<>cFile
  153.             oXbp1:setdata(cFile)
  154.         endif
  155.         cOldFile := cFile
  156.         nEvent := AppEvent( @mp1, @mp2, @oXbp )
  157.         if nEvent == xbeP_Keyboard .and. mp1 == xbeK_ESC
  158.             oXbp:handleEvent( nEvent, mp1, mp2 )
  159.             lExit := .T.
  160.             loop
  161.         elseif nEvent == xbeUser_Print
  162.             cFileName := alltrim(oXbp1:editbuffer())
  163.             if right(cFilename,1)='\'
  164.             elseif !file(cFilename).and.at('.',cFilename)=0
  165.                 cFilename    := cFilename+'.prg'
  166.             endif
  167.             if right(cFilename,1)=='\'
  168.                 cDirectry := cFileName
  169.                 aFiles    := directory(cFileName+'*.prg')
  170.                 oXbp1:setdata(cFileName+"*.prg")
  171.                 dStartdate    := ctod(oDateBox:XbpSLE:editbuffer())
  172.                 for i=1 to len(aFiles)
  173.                     if aFiles[i,F_DATE]>=dStartdate
  174.                         aAdd(aFileNames,upper(cDirectry)+alltrim(aFiles[i,F_NAME]))
  175.                     endif
  176.                 next i
  177.                 oXbp1:setdata(cDirectry)
  178.                 oXbp1:setMarked( {oXbp1:bufferlength,oXbp1:bufferlength} )
  179.                 setAppFocus(oXbp1)
  180.             elseif "*"$cFilename.or."?"$cFileName
  181.                 cDirectry := left(cFileName,rat("\",cFileName))
  182.                 cDir := cDirectry
  183.                 aFiles    := directory(cFileName)
  184.                 dStartdate    := ctod(oDateBox:XbpSLE:editbuffer())
  185.                 for i=1 to len(aFiles)
  186.                     if aFiles[i,F_DATE]>=dStartdate
  187.                         aAdd(aFileNames,upper(cDirectry)+alltrim(aFiles[i,F_NAME]))
  188.                     endif
  189.                 next i
  190.                 oXbp1:setdata(cDirectry)
  191.                 oXbp1:setMarked( {oXbp1:bufferlength,oXbp1:bufferlength} )
  192.                 setAppFocus(oXbp1)
  193.             endif
  194.             if !empty(aFileNames)
  195.                 oPrinterPS := PrinterPS()
  196.                 for i:=1 to len(aFileNames)
  197.                     ListFile(aFileNames[i],oPrinterPS)
  198.                 next i
  199.                 if oPrinterPS<>Nil
  200.                     oPrinterPS:destroy()
  201.                 endif
  202.                 cDir := left(aFileNames[1],rat("\",aFileNames[1]))
  203.                 cFile := ""
  204.                 aSize(aFileNames,0)
  205.             endif
  206.         elseif nEvent == xbeUser_Browse
  207.             cFile := aFileNames[1]
  208.             cDir := left(cFile,rat("\",cFile))
  209.             cfile := ""
  210.             aSize(aFileNames,0)
  211.         endif
  212.         oXbp:handleEvent( nEvent, mp1, mp2 )
  213.     enddo
  214.     oDlg:destroy()
  215.     setAppFocus(oFocus)
  216.  
  217. RETURN
  218.  
  219.  
  220. FUNCTION ListFile(cFilename,oPrinterPS)
  221.  
  222.     LOCAL cString := cString2 := "", cSearch := " ,+)}|\"
  223.     LOCAL nX, nY, cHeader, nMaxLen := 132, aAttr, aFiles, i, n:=1, oFontDlg, oFont, oFontBig
  224.     LOCAL nIndent, nDifference, lContinue := .F., nColor := GRA_CLR_BLACK
  225.  
  226.     if oPrinterPS==Nil
  227.         RETURN .F.
  228.     endif
  229.  
  230.     cString    := memoread(cFileName)
  231.     for i:=1 to 100
  232.         if substr(cString,i,1)$"`1234567890-=~!@#$%^&*()_+,./<>?;':[]\{}|"
  233.             *** OK ***
  234.         elseif substr(upper(cString),i,1)$"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  235.             *** OK ***
  236.         elseif substr(cString,i,1)$chr(9)+chr(10)+chr(32)+chr(34)+chr(13)
  237.             *** OK ***
  238.         else
  239.             MsgBox("Invalid Character detected in "+cFileName+chr(13)+str(asc(substr(cString,i,1))))
  240.             RETURN .F.
  241.         endif
  242.     next i
  243.  
  244.     nIndent := 5
  245.     do while len(cString)>2
  246.         nLen    := at(chr(13),cString)
  247.         cPrintstr    := rtrim(left(cString,nLen-1))
  248.         nDifference := len(cPrintStr)-len(alltrim(cPrintStr))
  249.         if nDifference>1.and.nDifference<nIndent
  250.             nIndent := nDifference
  251.         endif
  252.         cString    := right(cString,len(cString)-(nLen+1))
  253.     enddo
  254.  
  255.     cString := memoread(cFileName)
  256.  
  257.     aAttr := ARRAY( GRA_AS_COUNT )
  258.     aFiles := directory(cFilename)
  259.  
  260.         aPaperSize    := oPrinterPS:device():paperSize()
  261.         nWidth    := aPaperSize[1]    // Actual Width of Paper
  262.         nHeight    := aPaperSize[2]    // Actual Height of Paper
  263.         nSide        := aPaperSize[3]  // Left & Right Margins
  264.         nTopBottom    := aPaperSize[4]  // Top & Bottom Margins
  265.  
  266.         nLeft        := 0
  267.         nBottom    := 0
  268.         nRight    := nWidth-(nSide*2)-2
  269.         nTop        := nHeight-(nTopBottom*2)
  270.  
  271.     oPrinterPS:device():startDoc()
  272.  
  273.     oFontBig    := XbpFont():new(oPrinterPS)
  274.     oFontBig:create("16.Times New Roman Bold")
  275.  
  276.     oFont := NIL
  277.     if empty(oFont)
  278.         oFont := XbpFont():new(oPrinterPS)
  279.         oFont:create("8.Courier New")
  280.     endif
  281.  
  282.     GraSetFont(oPrinterPS,oFont)
  283.  
  284.     nX    := 0
  285.     nY    := 2500
  286.  
  287.     ln    := 0
  288.     nLen    := 1
  289.     nPage    := 1
  290.  
  291.     do while len(cString)>2 //.and.nLen>0
  292.         if nY==2500
  293.             GraSetFont(oPrinterPS,oFontBig)
  294.             GraSetColor(oPrinterPS,GRA_CLR_DARKRED)
  295.             aAttr [ GRA_AS_HORIZALIGN ] := GRA_HALIGN_CENTER
  296.             GraSetAttrString(oPrinterPS,aAttr)
  297.             GraStringAt(oPrinterPS,{1000,nY},upper(cFileName))
  298.             oFont:configure("10."+oFont:compoundName+" Bold")
  299.             GraSetFont(oPrinterPS,oFont)
  300.             GraStringAt(oPrinterPS,{1000,nY-50},"Last Modified on "+dtoc(aFiles[1,F_DATE])+" at "+aFiles[1,F_TIME])
  301.             GraStringAt(oPrinterPS,{1000,nY-90},"Printed on "+dtoc(date())+" at "+time())
  302.             nY    := nY-120
  303.             GraSetColor(oPrinterPS,GRA_CLR_BLACK)
  304.             aAttr [ GRA_AS_HORIZALIGN ]     := GRA_HALIGN_LEFT
  305.             GraSetAttrString(oPrinterPS,aAttr)
  306.         endif
  307.  
  308.         GraSetColor(oPrinterPS,GRA_CLR_BLACK)
  309.         ln    := ln+1
  310.         nY := nY-40
  311.         if nY<100
  312.             oFont:configure("10."+oFont:compoundName+" Bold")
  313.             GraSetFont(oPrinterPS,oFont)
  314.             GraSetColor(oPrinterPS,GRA_CLR_DARKRED)
  315.             GraStringAt(oPrinterPS,{nX,nY-40},padc('Page '+alltrim(str(nPage)),100))
  316.             nY    := 2500
  317.             oPrinterPS:device():newpage()
  318.             nPage    := nPage+1
  319.             loop
  320.         endif
  321.         nLen    := at(chr(13),cString)
  322.         cPrintstr    := rtrim(left(cString,nLen-1))
  323.         nSp := 0
  324.         do while left(cPrintStr,1)==" ".or.left(cPrintStr,1)==chr(9)
  325.             if left(cPrintStr,1)==" "
  326.                 nSp := nSp+1
  327.             else
  328.                 nSp := nSp+nIndent
  329.             endif
  330.             cPrintStr := right(cPrintStr,len(cPrintStr)-1)
  331.         enddo
  332.         nSp := round((nSp/nIndent),0)*5
  333.         if nSp>90
  334.             nSp := 30
  335.         endif
  336.         cLeftStr := space(nSp)
  337.         cRightStr := alltrim(cPrintstr)
  338.         if cRightStr == replicate(left(cRightStr,1),len(cRightStr)).and.(nSp+len(cRightStr))>75
  339.             cRightStr := replicate(left(cRightStr,1),75-nSp)
  340.         endif
  341.         cPrintstr := cLeftStr+cRightStr
  342.         cPrintStr := StrTran( cPrintStr,chr(9)," " )
  343.         cString2 := cString2+replicate(chr(9),nSp/nIndent)+cRightStr+chr(13)+chr(10)
  344.         if oFont:nominalPointSize<>8
  345.             oFont:configure("8."+oFont:compoundName+" Bold")
  346.             GraSetFont(oPrinterPS,oFont)
  347.             GraSetColor(oPrinterPS,GRA_CLR_BLACK)
  348.         endif
  349.         GraStringAt(oPrinterPS,{nX+100,nY},str(ln,5))
  350.         if !empty(left(cPrintStr,1)).and.len(cPrintStr)<=75
  351.             oFont:configure("10."+oFont:compoundName+" Bold")
  352.             GraSetFont(oPrinterPS,oFont)
  353.         elseif oFont:nominalPointSize<>8
  354.             oFont:configure("8."+oFont:compoundName)
  355.             GraSetFont(oPrinterPS,oFont)
  356.         endif
  357.  
  358.         cCheckStr :=upper(left(alltrim(cPrintStr),5))
  359.         if left(cCheckStr,1)$"*/".and.!lContinue
  360.             GraSetColor(oPrinterPS,GRA_CLR_DARKGREEN)
  361.         elseif left(cCheckStr,1)=="#".and.!lContinue
  362.             GraSetColor(oPrinterPS,GRA_CLR_BLUE)
  363.         elseif cCheckStr$"PROCEDURE|FUNCTION|RETURN|STATIC|INLINE|CLASS|ENDCLASS".and.!lContinue
  364.             GraSetColor(oPrinterPS,GRA_CLR_RED)
  365.         elseif (left(cCheckStr,2)=="IF".or.cCheckStr$"ENDIF|DO CASE|ENDCASE|DO WHILE|ENDDO").and.!lContinue
  366.             GraSetColor(oPrinterPS,GRA_CLR_DARKBLUE)
  367.         elseif cCheckStr$"LOCAL|PRIVATE|PUBLIC".and.!lContinue
  368.             GraSetColor(oPrinterPS,GRA_CLR_GREEN)
  369.         elseif !lContinue
  370.             GraSetColor(oPrinterPS,GRA_CLR_BLACK)
  371.         elseif lContinue
  372.             GraSetcolor(oPrinterPS,nColor)
  373.         endif
  374.         cCheckStr := upper(left(cPrintStr,5))
  375.         if cCheckStr$"METHOD".and.!lContinue
  376.             GraSetColor(oPrinterPS,GRA_CLR_RED)
  377.         endif
  378.         cPrintStr := alltrim(cPrintStr)
  379.  
  380.         nLength := 0
  381.         do while nSp+len(cPrintstr)>93
  382.             for i := 1 to len(cSearch)
  383.                 nSpace    := rat(substr(cSearch,i,1),left(cPrintstr,93-nSp))
  384.                 if nSpace<>0
  385.                     i:=len(cSearch)
  386.                 endif
  387.             next i
  388.             if nSpace==0
  389.                 nSpace := 93-nSp
  390.             endif
  391.             if oFont:nominalPointSize<>8
  392.                 oFont:configure("8."+oFont:compoundName+" Bold")
  393.                 GraSetFont(oPrinterPS,oFont)
  394.             endif
  395.             GraStringAt(oPrinterPS,{nX+100,nY},space(8+nSp)+alltrim(left(cPrintstr,nSpace))+" ;")
  396.             nY := nY-40
  397.             cPrintStr := alltrim(right(cPrintStr,len(cPrintStr)-nSpace))
  398.             if nSp+len(cPrintStr)<=90
  399.                 cPrintStr := space(3)+alltrim(cPrintStr)
  400.             endif
  401.         enddo
  402.         if !empty(cPrintStr)
  403.             if upper(left(alltrim(cPrintStr),4))$"ELSE|CASE"
  404.                 cPrintStr := space(2)+cPrintStr
  405.             endif
  406.             GraStringAt(oPrinterPS,{nX+100,nY},space(8+nSp)+cPrintStr)
  407.         endif
  408.         if right(cPrintStr,1)==";"
  409.             lContinue := .T.
  410.             nColor := GraSetColor(oPrinterPS)[1]
  411.         else
  412.             lContinue := .F.
  413.         endif
  414.         cString    := right(cString,len(cString)-(nLen+1))
  415.     enddo
  416.     if lUpDate
  417.         MemoWrit(cFileName,cString2)
  418.     endif
  419.     do while nY>=100
  420.         nY := nY-40
  421.     enddo
  422.     oFont:configure("10."+oFont:compoundName+" Bold")
  423.     GraSetFont(oPrinterPS,oFont)
  424.     GraSetColor(oPrinterPS,GRA_CLR_DARKRED)
  425.     GraStringAt(oPrinterPS,{nX,nY-40},padc('Page '+alltrim(str(nPage)),100))
  426.     oPrinterPS:device():endDoc()
  427.  
  428. RETURN .T.
  429.  
  430.  
  431.  
  432.  
  433. FUNCTION SelectFont(oPS,cTitle,cDefaultFont)
  434.  
  435.     LOCAL oFont, oFontDlg
  436.     LOCAL oCrt, oWin := setAppWindow(), oFocus := setAppFocus()
  437.  
  438.     DEFAULT cTitle to "View Fonts"
  439.     DEFAULT cDefaultFont to "Arial"
  440.  
  441.       oCrt := XbpCrt():new( , , {0,0}, 25, 80, "") 
  442.       oCrt:clipChildren := .F.
  443.       oCrt:create() 
  444.  
  445.       SetAppWindow( oCrt )     
  446.  
  447.       // Create XbpFontDialog object 
  448.  
  449.       oFontDlg            := XbpFontDialog():new(,,,oPS)
  450.       oFontDlg:familyName := cDefaultFont
  451.     oFontDlg:title      := cTitle
  452.       oFontDlg:create()                // Request font dialog
  453.  
  454.       // Allow font to be selected 
  455.       // using modal operation
  456.  
  457.     oFont := oFontDlg:display( XBP_DISP_APPMODAL )
  458.  
  459.       oFontDlg:destroy( )               // Destroy font dialog
  460.     oCrt:destroy()
  461.     setAppWindow( oWin )
  462.     setAppFocus( oFocus )
  463.  
  464. RETURN oFont
  465.  
  466.  
  467.  
  468. STATIC FUNCTION PrinterPS()
  469.     LOCAL oPS := Nil
  470.     LOCAL oDC := SetPrinter(.T.,,,.T.)
  471.     LOCAL oFocus := setAppFocus()
  472.     
  473.     if oDC<>Nil
  474.         oPS:=XbpPresSpace():new()
  475.         oPS:Create( oDC, {oDC:paperSize()[1],oDC:paperSize()[2]}, GRA_PU_LOMETRIC )
  476.     endif
  477.     setAppFocus(oFocus)
  478. RETURN oPS
  479.